import java.util.*;
public class nk13591{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(fun(a,n,m));
    }
    static int fun(int[] a,int n,int m){
        if(n<=1){
            return 0;
        }
        int i=0;int j=1;
        int count=0;
        do{
            if(a[j]-a[i]<m){
                count++;
                i+=2;
                j+=2;
            }else {
                i++;
                j++;
            }
            
        }while(j<=n-1);
        return count;
    }
}